import {Coolcar} from "./request";

export namespace CarService{
    export function subscribe(onMsg:any){
        const socket = wx.connectSocket({
            url:Coolcar.wsAddr+"/ws"
        })

        socket.onMessage((msg)=>{
            const obj = JSON.parse(msg.data as string)
            onMsg(obj)
        })
        return socket
    }

    export function getCar(id:string):Promise<any>{
        return Coolcar.sendRequestWithAuthRetry({
            method: "GET",
            path: `/v1/car/${encodeURIComponent(id)}`,
        })
    }
}